/********************************************************************************
 * @Author: Zhenzhou Liu
 * @Date: 2024-11-19
 * @Description: Cg分治练习之使用快速排序找到第K个最小元素
 *******************************************************************************/

#include <iostream>
#include <vector>
#include <sstream>

using namespace std;

int partition(vector<int>& nums, int low, int high) {
    int pivot = nums[high];
    int i = low - 1;
    for (int j = low; j < high; ++j) {
        if (nums[j] < pivot) {
            ++i;
            swap(nums[i], nums[j]);
        }
    }
    ++i;
    swap(nums[i], nums[high]);
    return i;
}

int randomizedPartition(vector<int>& nums, int low, int high) {
    int s = low + rand() % (high - low + 1);
    swap(nums[s], nums[high]);
    return partition(nums, low, high);
}

int quickSortFindKthSmallest(vector<int>& nums, int low, int high, int k) {
    int s = randomizedPartition(nums, low, high);
    int target = s - low + 1;
    if (target == k) {
        return nums[s];
    }
    else if (target > k) {
        return quickSortFindKthSmallest(nums, low, s - 1, k);
    } else {
        return quickSortFindKthSmallest(nums, s + 1, high, k - target);
    }
}

int main() {
    string input;
    getline(cin, input);
    int i = 0, temp, n = 0, k = 0;
    vector<int> nums;
    stringstream ss(input);
    while (ss >> temp) {
        if (ss.peek() == ',') {
            ss.ignore();
        }
        if (i == 0) {
            n = temp;
        } else if (i == 1) {
            k = temp;
        } else {
            nums.push_back(temp);
        }
        ++i;
    }
    srand((unsigned) time(NULL));
    cout << quickSortFindKthSmallest(nums, 0, n - 1, k);
    return 0;
}
